home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Table / Sources / Linking.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  25.6 KB  |  777 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Linking.cpp
  4. //    Release Version:    $ ODF 2 $ 
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef LINKING_H
  11. #include "Linking.h"
  12. #endif
  13.  
  14. #ifndef PART_H
  15. #include "Part.h"
  16. #endif
  17.  
  18. #ifndef SELECTION_H
  19. #include "Selection.h"
  20. #endif
  21.  
  22. #ifndef COMMANDS_H
  23. #include "Commands.h"
  24. #endif
  25.  
  26. #ifndef PROXY_H
  27. #include "Proxy.h"
  28. #endif
  29.  
  30. #ifndef FRAME_H
  31. #include "Frame.h"
  32. #endif
  33.  
  34. #ifndef CONTENT_H
  35. #include "Content.h"
  36. #endif
  37.  
  38. // ----- Framework Includes -----
  39.  
  40. #ifndef FWPART_H
  41. #include "FWPart.h"
  42. #endif
  43.  
  44. #ifndef FWFRAME_H
  45. #include "FWFrame.h"
  46. #endif
  47.  
  48. #ifndef FWITERS_H
  49. #include "FWIters.h"
  50. #endif
  51.  
  52. #ifndef FWPRESEN_H
  53. #include "FWPresen.h"
  54. #endif
  55.  
  56. #ifndef FWSELECT_H
  57. #include "FWSelect.h"
  58. #endif
  59.  
  60. // for FW_CCloneInfo
  61. #ifndef FWPROXY_H
  62. #include "FWProxy.h"
  63. #endif
  64.  
  65. // for FW_SUForceFocus
  66. #ifndef FWUTIL_H
  67. #include "FWUtil.h"
  68. #endif
  69.  
  70. #ifndef FWPXYFRM_H
  71. #include "FWPxyFrm.h"
  72. #endif
  73.  
  74. #ifndef FWPRTITE_H
  75. #include "FWPrtIte.h"
  76. #endif
  77.  
  78. #ifndef FWUTIL_H
  79. #include "FWUtil.h"
  80. #endif
  81.  
  82. #ifndef FWCLNINF_H
  83. #include "FWClnInf.h"
  84. #endif
  85.  
  86. #ifndef FWPXYITE_H
  87. #include "FWPxyIte.h"
  88. #endif
  89.  
  90. #ifndef FWLNKITE_H
  91. #include "FWLnkIte.h"
  92. #endif
  93.  
  94. #ifndef FWINTER_H
  95. #include "FWInter.h"
  96. #endif
  97.  
  98. // ----- OS Includes -----
  99.  
  100. #ifndef FWODEXCE_H
  101. #include "FWODExce.h"
  102. #endif
  103.  
  104. #ifndef FWODMISC_H
  105. #include "FWODMisc.h"
  106. #endif
  107.  
  108. #ifndef FWLINSHP_H
  109. #include "FWLinShp.h"
  110. #endif
  111.  
  112. // ----- Foundation Includes -----
  113.  
  114. #ifndef FWMEMMGR_H
  115. #include "FWMemMgr.h"
  116. #endif
  117.  
  118. // ----- OpenDoc Includes -----
  119.  
  120. #ifndef SOM_Module_OpenDoc_StdProps_defined
  121. #include <StdProps.xh>
  122. #endif
  123.  
  124. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  125. #include <StdTypes.xh>
  126. #endif
  127.  
  128. #ifndef SOM_ODStorageUnit_xh
  129. #include <StorageU.xh>
  130. #endif
  131.  
  132. #ifndef SOM_ODStorageUnitView_xh
  133. #include <SUView.xh>
  134. #endif
  135.  
  136. #ifndef SOM_ODLink_xh
  137. #include <Link.xh>
  138. #endif
  139.  
  140. #ifndef SOM_ODLinkSpec_xh
  141. #include <LinkSpec.xh>
  142. #endif
  143.  
  144. #ifndef SOM_ODLinkSource_xh
  145. #include <LinkSrc.xh>
  146. #endif
  147.  
  148. #ifndef SOM_ODSession_xh
  149. #include <ODSessn.xh>
  150. #endif
  151.  
  152. //========================================================================================
  153. // Constants
  154. //========================================================================================
  155.  
  156. #define kPublishFormat "Apple:ODF:Publish:ODFTable"
  157. #define kSubscribeFormat "Apple:ODF:Subscribe:ODFTable"
  158.  
  159. //========================================================================================
  160. // Runtime Information
  161. //========================================================================================
  162.  
  163. #ifdef FW_BUILD_MAC
  164. #pragma segment opftable
  165. #endif
  166.  
  167. //========================================================================================
  168. // Global Functions
  169. //========================================================================================
  170.  
  171. ODShape* CreateLinkBorderShape(Environment* ev, CCell cell, CTablePartContent* content);
  172. void CommonDrawLinkBorder(Environment* ev, ODShape* outline, FW_CGraphicContext& gc, FW_Boolean selected);
  173.  
  174. //----------------------------------------------------------------------------------------
  175. //    CreateLinkBorderShape
  176. //----------------------------------------------------------------------------------------
  177. ODShape* CreateLinkBorderShape(Environment* ev, CCell cell, CTablePartContent* content)
  178. {
  179.     FW_CRect rect;
  180.     content->FindRect(cell, rect);
  181.     ODShape* shape = ::FW_NewODShape(ev, rect);
  182.     return shape;
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    CommonDrawLinkBorder
  187. //----------------------------------------------------------------------------------------
  188. void CommonDrawLinkBorder(Environment* ev, ODShape* outline, FW_CGraphicContext& gc, FW_Boolean selected)
  189. {
  190.     FW_CRect box;
  191.     outline->GetBoundingBox(ev, (ODRect*)&box);
  192.  
  193.     FW_CStyle horzStyle(FW_IntToFixed(FW_kLinkBorderWidth), FW_kHLinkPat);
  194.     FW_CStyle vertStyle(FW_IntToFixed(FW_kLinkBorderWidth), FW_kVLinkPat);
  195.     FW_CInk ink(FW_kXOr);
  196.  
  197.     if (selected)
  198.     {
  199.         horzStyle.SetPattern(FW_kSelectedHLinkPat);
  200.         vertStyle.SetPattern(FW_kSelectedVLinkPat);
  201.     }
  202.  
  203.     FW_CLineShape topLine(box.TopLeft(), box.TopRight(), ink, horzStyle);
  204.     FW_CLineShape bottomLine(box.BotLeft(), box.BotRight(), ink, horzStyle);
  205.     FW_CLineShape leftLine(box.TopLeft(), box.BotLeft(), ink, vertStyle);
  206.     FW_CLineShape rightLine(box.TopRight(), box.BotRight(), ink, vertStyle);
  207.  
  208.     topLine.Render(gc);
  209.     bottomLine.Render(gc);
  210.     leftLine.Render(gc);
  211.     rightLine.Render(gc);
  212. }
  213.  
  214. //========================================================================================
  215. //    class CTableLinkSource
  216. //========================================================================================
  217.  
  218. //----------------------------------------------------------------------------------------
  219. //    CTableLinkSource constructor
  220. //----------------------------------------------------------------------------------------
  221.  
  222. CTableLinkSource::CTableLinkSource(    Environment* ev, ODUpdateID changeID, 
  223.                                     FW_CPresentation* presentation,
  224.                                     CTablePart* part,
  225.                                     CTablePartContent* content,
  226.                                     CTableSelection* selection)
  227. :    FW_CLinkSource(ev, changeID, presentation),
  228.     fTablePart(part),
  229.     fPublishedContent(NULL)
  230. {
  231.     fPublishedContent = FW_NEW(CTableSelectionContent, (ev, part, content));
  232.     fPublishedContent->SetCell(selection->GetSelectedCell());
  233. }
  234.  
  235. //----------------------------------------------------------------------------------------
  236. //    CTableLinkSource destructor
  237. //----------------------------------------------------------------------------------------
  238.  
  239. CTableLinkSource::~CTableLinkSource()
  240. {
  241. }
  242.  
  243. //----------------------------------------------------------------------------------------
  244. //    CTableLinkSource::LinkEstablished
  245. //----------------------------------------------------------------------------------------
  246.  
  247. void CTableLinkSource::LinkEstablished(Environment* ev)
  248. {
  249.     //---- Change the link status of affected embedded frames
  250.     fTablePart->ChangeFrameStatus(ev, fPublishedContent->GetCell(), kODInLinkSource);
  251. }
  252.  
  253. //----------------------------------------------------------------------------------------
  254. //    CTableLinkSource::DoExternalizeLink
  255. //----------------------------------------------------------------------------------------
  256.  
  257. void CTableLinkSource::DoExternalizeLink(Environment* ev, 
  258.                                         ODStorageUnit* storageUnit,
  259.                                         FW_CCloneInfo* cloneInfo)
  260. {
  261. FW_UNUSED(cloneInfo);
  262.     //-- Write out data specific to this part's publisher --
  263.     CCell cell = fPublishedContent->GetCell();        // table cell associated with this publisher
  264.     FW_CByteArray byteArray(&cell, sizeof(CCell));
  265.     storageUnit->SetValue(ev, byteArray);
  266. }
  267.  
  268. //----------------------------------------------------------------------------------------
  269. //    CTableLinkSource::ExternalizeLinkContent
  270. //----------------------------------------------------------------------------------------
  271.  
  272. void CTableLinkSource::ExternalizeLinkContent(Environment* ev, ODStorageUnit* linkSU)
  273. {
  274.     // -- Pick a frame, any frame --
  275.     FW_CPresentationFrameIterator piter(ev, fPresentation);
  276.     FW_CFrame* frame = piter.First(ev);
  277.     FW_ASSERT(frame);
  278.  
  279.     fDataInterchange->ExternalizeData(ev, fPublishedContent, frame, linkSU, FW_kLinkStorage, kODCloneToLink);
  280. }
  281.  
  282. //----------------------------------------------------------------------------------------
  283. //    CTableLinkSource::HasEmbeddedFrame
  284. //---------------------------------------------------------------------------------------
  285. FW_Boolean CTableLinkSource::HasEmbeddedFrame(Environment* ev, ODFrame* odFrame)
  286. {
  287.     // Is odFrame involved in this link source? (called by Part::EmbeddedFrameChanged)
  288.  
  289.     FW_Boolean result = false;
  290.  
  291.     // --- Find out whether odFrame is involved in any link source ---
  292.     if (odFrame->GetLinkStatus(ev) == kODInLinkSource)
  293.     {
  294.         CTableProxy* proxy = fPublishedContent->GetSelectedProxy(ev);
  295.         FW_CProxyProxyFrameIterator iter((FW_MProxy*) proxy);
  296.         for (FW_CProxyFrame* proxyFrame = iter.First(); iter.IsNotComplete(); proxyFrame = iter.Next())
  297.             if (proxyFrame->GetFrame(ev) == odFrame)
  298.             {
  299.                 result = true;
  300.                 break;
  301.             }
  302.     }
  303.  
  304.     return result;
  305. }
  306.  
  307. //----------------------------------------------------------------------------------------
  308. // CTableLinkSource::BreakLink
  309. //----------------------------------------------------------------------------------------
  310. void CTableLinkSource::BreakLink(Environment* ev)
  311. {
  312.     FW_CLinkSource::BreakLink(ev);
  313.  
  314.     //--- Erase Link Borders ---
  315.     fPresentation->Invalidate(ev);    // force all frames to be redrawn
  316.  
  317.     //--- Change status of embedded frames ---
  318.     fTablePart->ChangeFrameStatus(ev, fPublishedContent->GetCell(), kODNotInLink);
  319. }
  320.  
  321. //----------------------------------------------------------------------------------------
  322. //    CTableLinkSource::RevealLinkSource
  323. //---------------------------------------------------------------------------------------
  324. void CTableLinkSource::RevealLinkSource(Environment* ev, FW_CFrame* frame)
  325. {
  326. FW_UNUSED(frame);
  327.     CTableSelection* selection = fTablePart->GetTableSelection(ev);
  328.     selection->Select(ev, fPublishedContent->GetCell());
  329. }
  330.  
  331. //----------------------------------------------------------------------------------------
  332. // CTableLinkSource::GetCell
  333. //----------------------------------------------------------------------------------------
  334. CCell CTableLinkSource::GetCell(Environment* ev) const
  335. {
  336. FW_UNUSED(ev);
  337.     return fPublishedContent->GetCell();
  338. }
  339.  
  340. //----------------------------------------------------------------------------------------
  341. // CTableLinkSource::SetCell
  342. //----------------------------------------------------------------------------------------
  343. void CTableLinkSource::SetCell(Environment* ev, const CCell& cell)
  344. {
  345. FW_UNUSED(ev);
  346.     fPublishedContent->SetCell(cell);
  347. }
  348.  
  349. //----------------------------------------------------------------------------------------
  350. // CTableLinkSource::DoCreateLinkBorderShape
  351. //----------------------------------------------------------------------------------------
  352. ODShape* CTableLinkSource::DoCreateLinkBorderShape(Environment* ev)
  353. {
  354.     return CreateLinkBorderShape(ev, GetCell(ev), fTablePart->GetTableContent(ev));
  355. }
  356.  
  357. //----------------------------------------------------------------------------------------
  358. // CTableLinkSource::DoDrawLinkBorder
  359. //----------------------------------------------------------------------------------------
  360. void CTableLinkSource::DoDrawLinkBorder(Environment* ev, ODShape* outline, FW_CGraphicContext& gc)
  361. {
  362.     CommonDrawLinkBorder(ev, outline, gc, this->IsLinkSelected(ev));
  363. }
  364.  
  365. //----------------------------------------------------------------------------------------
  366. // CTableLinkSource::RestoreLink
  367. //----------------------------------------------------------------------------------------
  368. void  CTableLinkSource::RestoreLink(Environment* ev, FW_CPart* part)
  369. {
  370.     FW_CLinkSource::RestoreLink(ev, part);
  371.     
  372.     //---- Change the link status of affected embedded frames
  373.     fTablePart->ChangeFrameStatus(ev, fPublishedContent->GetCell(), kODInLinkSource);
  374. }
  375.  
  376.  
  377. //========================================================================================
  378. //    class CTableLink
  379. //========================================================================================
  380.  
  381. //----------------------------------------------------------------------------------------
  382. //    CTableLink constructor
  383. //----------------------------------------------------------------------------------------
  384.  
  385. CTableLink::CTableLink(    Environment* ev, 
  386.                         ODLink* odLink,
  387.                         ODLinkInfo* linkInfo, 
  388.                         FW_CPresentation* presentation,
  389.                         CTablePart* part,
  390.                         CTablePartContent* content,
  391.                         CTableSelection* selection) 
  392. :    FW_CLinkDestination(ev, odLink, linkInfo, presentation),
  393.     fTablePart(part),
  394.     fLinkedContent(NULL)
  395. {
  396.     //---- Create a new content object ----
  397.     fLinkedContent = FW_NEW(CTableSelectionContent, (ev, part, content));
  398.     fLinkedContent->SetCell(selection->GetSelectedCell());
  399. }
  400.  
  401. //----------------------------------------------------------------------------------------
  402. //    CTableLink destructor
  403. //----------------------------------------------------------------------------------------
  404.  
  405. CTableLink::~CTableLink()
  406. {
  407. }
  408.  
  409. //----------------------------------------------------------------------------------------
  410. //    CTableLink::LinkEstablished
  411. //----------------------------------------------------------------------------------------
  412.  
  413. void CTableLink::LinkEstablished(Environment* ev)
  414. {
  415.     fTablePart->ChangeFrameStatus(ev, fLinkedContent->GetCell(), kODInLinkDestination);
  416. }
  417.  
  418. //----------------------------------------------------------------------------------------
  419. //    CTableLink::DoUpdateLink
  420. //--------------------------------------------------------------------
  421. FW_Boolean CTableLink::DoUpdateLink(Environment* ev, ODStorageUnit* linkContentSU, ODPasteAsResult* embedInfo)
  422. {
  423.     FW_CPresentationFrameIterator piter(ev, fPresentation);
  424.     FW_CFrame* frame = piter.First(ev);
  425.     FW_ASSERT(frame);
  426.  
  427.     //-- Read data from the linkContentSU --
  428.     FW_Boolean result = (fDataInterchange->InternalizeData(ev, fLinkedContent, frame, linkContentSU, 
  429.                                                     FW_kLinkStorage, kODCloneFromLink, embedInfo)
  430.                                                     != FW_kInternalizeFailed);
  431.     if (result)
  432.         fPresentation->Invalidate(ev);    // force all frames to be redrawn
  433.     return result;
  434. }
  435.  
  436. //----------------------------------------------------------------------------------------
  437. // CTableLink::BreakLink
  438. //----------------------------------------------------------------------------------------
  439. void CTableLink::BreakLink(Environment* ev)
  440. {
  441.     FW_CLinkDestination::BreakLink(ev);
  442.  
  443.     //--- Erase Link Borders ---
  444.     fPresentation->Invalidate(ev);    // force all frames to be redrawn
  445.  
  446.     //--- Change status of embedded frames ---
  447.     fTablePart->ChangeFrameStatus(ev, fLinkedContent->GetCell(), kODNotInLink);
  448. }
  449.  
  450. //----------------------------------------------------------------------------------------
  451. //    CTableLink::DoExternalizeLink
  452. //----------------------------------------------------------------------------------------
  453.  
  454. void CTableLink::DoExternalizeLink(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
  455. {
  456. FW_UNUSED(cloneInfo);
  457.     // Write out data specific to this part's subscriber
  458.     CCell cell = fLinkedContent->GetCell();                // table cell associated with this link
  459.     FW_CByteArray byteArray(&cell, sizeof(CCell));
  460.     storageUnit->SetValue(ev, byteArray);
  461. }
  462.  
  463. //----------------------------------------------------------------------------------------
  464. // CTableLink::GetCell
  465. //----------------------------------------------------------------------------------------
  466. CCell CTableLink::GetCell(Environment* ev) const
  467. {
  468. FW_UNUSED(ev);
  469.     return fLinkedContent->GetCell();
  470. }
  471.  
  472. //----------------------------------------------------------------------------------------
  473. // CTableLink::SetCell
  474. //----------------------------------------------------------------------------------------
  475. void CTableLink::SetCell(Environment* ev, const CCell& cell)
  476. {
  477. FW_UNUSED(ev);
  478.     fLinkedContent->SetCell(cell);
  479. }
  480.  
  481. //----------------------------------------------------------------------------------------
  482. // CTableLink::DoCreateLinkBorderShape
  483. //----------------------------------------------------------------------------------------
  484. ODShape* CTableLink::DoCreateLinkBorderShape(Environment* ev)
  485. {
  486.     return CreateLinkBorderShape(ev, GetCell(ev), fTablePart->GetTableContent(ev));
  487. }
  488.  
  489. //----------------------------------------------------------------------------------------
  490. // CTableLink::DoDrawLinkBorder
  491. //----------------------------------------------------------------------------------------
  492. void CTableLink::DoDrawLinkBorder(Environment* ev, ODShape* outline, FW_CGraphicContext& gc)
  493. {
  494.     CommonDrawLinkBorder(ev, outline, gc, this->IsLinkSelected(ev));
  495. }
  496.  
  497. //----------------------------------------------------------------------------------------
  498. // CTableLink::GetContainingFrame
  499. //----------------------------------------------------------------------------------------
  500. FW_CFrame* CTableLink::GetContainingFrame(Environment* ev, ODFrame* odEmbeddedFrame)
  501. {
  502.     // Is odEmbeddedFrame involved in this link? (called by FW_CLinkManager::EditInLinkAttempted)
  503.  
  504.     if (odEmbeddedFrame->GetLinkStatus(ev) == kODInLinkDestination)
  505.     {
  506.         CTableProxy* proxy = fLinkedContent->GetSelectedProxy(ev);
  507.         FW_CProxyProxyFrameIterator iter((FW_MProxy*) proxy);
  508.         for (FW_CProxyFrame* proxyFrame = iter.First(); iter.IsNotComplete(); proxyFrame = iter.Next())
  509.         {
  510.             if (proxyFrame->GetFrame(ev) == odEmbeddedFrame)
  511.                 return proxyFrame->GetContainingFrame(ev);
  512.         }
  513.     }
  514.  
  515.     return NULL;
  516. }
  517.  
  518. //========================================================================================
  519. //    class CTableLinkManager
  520. //========================================================================================
  521.  
  522. FW_DEFINE_AUTO(CTableLinkManager)
  523.  
  524. //----------------------------------------------------------------------------------------
  525. //    CTableLinkManager constructor
  526. //----------------------------------------------------------------------------------------
  527.  
  528. CTableLinkManager::CTableLinkManager(Environment* ev, CTablePart* thePart, CTablePartContent* tableContent) :
  529.     FW_CLinkManager(ev, (FW_CPart*)thePart),
  530.     fTablePart(thePart),
  531.     fTableContent(tableContent)
  532. {
  533. }
  534.  
  535. //----------------------------------------------------------------------------------------
  536. //    CTableLinkManager destructor
  537. //----------------------------------------------------------------------------------------
  538.  
  539. CTableLinkManager::~CTableLinkManager()
  540. {
  541. }
  542.  
  543. //----------------------------------------------------------------------------------------
  544. //    CTableLinkManager::NewLinkSource
  545. //----------------------------------------------------------------------------------------
  546.  
  547. FW_CLinkSource* CTableLinkManager::NewLinkSource(Environment* ev, 
  548.                                                  ODUpdateID changeID, 
  549.                                                  FW_CPresentation* presentation)
  550. {
  551.     return new CTableLinkSource(ev, changeID, presentation, fTablePart, fTableContent, fTablePart->GetTableSelection(ev));
  552. }
  553.  
  554. //----------------------------------------------------------------------------------------
  555. //    CTableLinkManager::NewLinkDestination
  556. //----------------------------------------------------------------------------------------
  557.  
  558. FW_CLinkDestination* CTableLinkManager::NewLinkDestination(Environment* ev, ODLink *odLink,
  559.                                                         ODLinkInfo* linkInfo,
  560.                                                         FW_CPresentation* presentation)
  561. {
  562.     return new CTableLink(ev, odLink, linkInfo, presentation, fTablePart, fTableContent, fTablePart->GetTableSelection(ev));
  563. }
  564.  
  565. //----------------------------------------------------------------------------------------
  566. //    CTableLinkManager::DoChangeLinkStatus
  567. //----------------------------------------------------------------------------------------
  568.  
  569. void CTableLinkManager::DoChangeLinkStatus(Environment* ev, ODFrame* odFrame)
  570. {
  571.     // call ODFrame::ChangeLinkStatus on any embedded frames that are involved in a link
  572.     // when a link is created, broken, moved, etc.
  573.     // odFrame is the frame of this part whose link status has changed.
  574.     
  575.     FW_CEmbeddingFrame* frame = FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(ev, odFrame);
  576.     if (frame)
  577.     {
  578.         ODLinkStatus linkStatus = odFrame->GetLinkStatus(ev);
  579.  
  580.         // Only need to propagate linkStatus to embedded frames that don't participate in
  581.         // any of this part's links; otherwise their local link status takes precedence.
  582.  
  583.         CTableProxysIterator iter(fTableContent);
  584.         for (CTableProxy* proxy = iter.First(); iter.IsNotComplete(); proxy = iter.Next())
  585.         {
  586.             if (!this->IsCellInLink(ev, proxy->GetCell()))
  587.             {
  588.                 FW_CProxyEmbeddedFrameIterator efiter(ev, proxy);
  589.                 for (ODFrame* embFrame = efiter.First(ev); efiter.IsNotComplete(ev); embFrame = efiter.Next(ev))
  590.                     embFrame->ChangeLinkStatus(ev, linkStatus);
  591.             }
  592.         }
  593.     }
  594. }
  595.  
  596. //----------------------------------------------------------------------------------------
  597. //    CTableLinkManager::GetSourceLinkFormat, GetDestLinkFormat
  598. //----------------------------------------------------------------------------------------
  599. ODValueType    CTableLinkManager::GetSourceLinkFormat(Environment* ev)
  600. {
  601. FW_UNUSED(ev);
  602.     // Must be different from subscribe format!
  603.     return kPublishFormat;
  604. }
  605.  
  606. ODValueType    CTableLinkManager::GetDestLinkFormat(Environment* ev)
  607. {
  608. FW_UNUSED(ev);
  609.     // Must be different from publish format!
  610.     return kSubscribeFormat;
  611. }
  612.  
  613. //----------------------------------------------------------------------------------------
  614. //    CTableLinkManager::IsCellInLink
  615. //----------------------------------------------------------------------------------------
  616. FW_Boolean CTableLinkManager::IsCellInLink(Environment* ev, const CCell& cell)
  617. {
  618.     //--- Check whether the cell participates in any of our source links
  619.     FW_CLinkMgrLinkSourceIterator sit(this);
  620.     for (CTableLinkSource* publisher = (CTableLinkSource*)sit.First(); sit.IsNotComplete(); 
  621.             publisher = (CTableLinkSource*)sit.Next())
  622.     {
  623.         if (publisher->GetCell(ev) == cell)
  624.             return true;
  625.     }
  626.  
  627.     //--- Check whether the cell participates in any of our destination links
  628.     FW_CLinkMgrLinkDestIterator dit(this);
  629.     for (CTableLink* link = (CTableLink*)dit.First(); dit.IsNotComplete(); link = (CTableLink*)dit.Next())
  630.     {
  631.         if (link->GetCell(ev) == cell)
  632.             return true;
  633.     }
  634.  
  635.     return false;
  636. }
  637.  
  638. //----------------------------------------------------------------------------------------
  639. // CTableLinkManager::CellToSourceLink
  640. //----------------------------------------------------------------------------------------
  641. CTableLinkSource* CTableLinkManager::CellToSourceLink(Environment* ev, const CCell& cell) const
  642. {
  643.     FW_CLinkMgrLinkSourceIterator iter(this);
  644.     for (CTableLinkSource* slink = (CTableLinkSource*)iter.First(); iter.IsNotComplete(); 
  645.             slink = (CTableLinkSource*)iter.Next())
  646.     {
  647.         if (slink->GetCell(ev) == cell)
  648.             return slink;
  649.     }
  650.  
  651.     return NULL;
  652. }
  653.  
  654. //----------------------------------------------------------------------------------------
  655. // CTableLinkManager::CellToLink
  656. //----------------------------------------------------------------------------------------
  657. CTableLink* CTableLinkManager::CellToLink(Environment* ev, const CCell& cell) const
  658. {
  659.     FW_CLinkMgrLinkDestIterator iter(this);
  660.     for (CTableLink* link = (CTableLink*)iter.First(); iter.IsNotComplete(); 
  661.             link = (CTableLink*)iter.Next())
  662.     {
  663.         if (link->GetCell(ev) == cell)
  664.             return link;
  665.     }
  666.  
  667.     return NULL;
  668. }
  669.  
  670. //----------------------------------------------------------------------------------------
  671. //    CTableLinkManager::DoInternalizeOneSourceLink
  672. //---------------------------------------------------------------------------------------
  673.  
  674. FW_CLinkSource* CTableLinkManager::DoInternalizeOneSourceLink(Environment* ev, 
  675.                                                               ODStorageUnit* storageUnit,
  676.                                                               ODUpdateID updateID)
  677. {
  678.     //-- Read the link source's cell
  679.     CCell cell;
  680.     FW_CByteArray byteArray;
  681.     storageUnit->GetValue(ev, sizeof(CCell), byteArray);
  682.     byteArray.CopyBuffer(&cell, sizeof(CCell));
  683.  
  684.     //-- Create and add a publisher to represent the link source
  685.     CTableLinkSource* publisher = (CTableLinkSource*)this->NewLinkSource(ev, 
  686.                                         updateID, fTablePart->fTablePresentation);
  687.     publisher->SetCell(ev, cell);
  688.     fTablePart->ChangeFrameStatus(ev, cell, kODInLinkSource);
  689.  
  690.     return publisher;
  691. }
  692.  
  693. //----------------------------------------------------------------------------------------
  694. //    CTableLinkManager::DoInternalizeOneDestLink
  695. //---------------------------------------------------------------------------------------
  696.  
  697. FW_CLinkDestination* CTableLinkManager::DoInternalizeOneDestLink(Environment* ev, 
  698.                                                                ODStorageUnit* storageUnit,
  699.                                                                ODLink* odLink, 
  700.                                                                ODLinkInfo* linkInfo)
  701. {
  702.     //-- Read the link's cell
  703.     CCell cell;
  704.     FW_CByteArray byteArray;
  705.     storageUnit->GetValue(ev, sizeof(CCell), byteArray);
  706.     byteArray.CopyBuffer(&cell, sizeof(CCell));
  707.  
  708.     //-- Create and add a subscriber to represent the link
  709.     CTableLink* subscriber = (CTableLink*)this->NewLinkDestination(ev, 
  710.                                             odLink, linkInfo, fTablePart->fTablePresentation);
  711.     subscriber->SetCell(ev, cell);
  712.     return subscriber;
  713. }
  714.  
  715. //----------------------------------------------------------------------------------------
  716. //    CTableLinkManager::UpdateLinkSource
  717. //----------------------------------------------------------------------------------------
  718.  
  719. void CTableLinkManager::UpdateLinkSource(Environment* ev, ODUpdateID updateID)
  720. {
  721.     CTableLinkSource* linkSource = this->GetSelectedLinkSource(ev);
  722.     if (linkSource)
  723.         linkSource->ContentUpdated(ev, updateID);
  724. }
  725.  
  726. //----------------------------------------------------------------------------------------
  727. //    CTableLinkManager::GetSelectedLinkSource
  728. //----------------------------------------------------------------------------------------
  729. CTableLinkSource* CTableLinkManager::GetSelectedLinkSource(Environment* ev)
  730. {
  731.     FW_CLinkMgrLinkSourceIterator iter(this);
  732.     for (CTableLinkSource* slink = (CTableLinkSource*)iter.First(); iter.IsNotComplete(); 
  733.             slink = (CTableLinkSource*)iter.Next())
  734.     {
  735.         if (slink->IsLinkSelected(ev))
  736.             return slink;
  737.     }
  738.     return NULL;    
  739. }
  740.  
  741. //----------------------------------------------------------------------------------------
  742. //    CTableLinkManager::BreakExistingLinks
  743. //----------------------------------------------------------------------------------------
  744. void CTableLinkManager::BreakExistingLinks(Environment* ev, const CCell& cell)
  745. {
  746.     //-- Check for a link being broken --
  747.     CTableLinkSource* linkSource = this->CellToSourceLink(ev, cell);
  748.     if (linkSource)
  749.     {
  750.         this->BreakSourceLink(ev, linkSource);
  751.         delete linkSource;
  752.     }
  753.     CTableLink* link = this->CellToLink(ev, cell);
  754.     if (link)
  755.     {
  756.         this->BreakDestinationLink(ev, link);
  757.         delete link;
  758.     }
  759. }
  760.  
  761. //----------------------------------------------------------------------------------------
  762. //    CTableLinkManager::MoveExistingLinks
  763. //----------------------------------------------------------------------------------------
  764. void CTableLinkManager::MoveExistingLinks(Environment* ev,
  765.                                           const CCell& fromCell,
  766.                                           const CCell& toCell)
  767. {
  768.     //-- Adjust affected links --
  769.     CTableLinkSource* slink = this->CellToSourceLink(ev, fromCell);
  770.     if (slink)
  771.         slink->SetCell(ev, toCell);
  772.     CTableLink* link = this->CellToLink(ev, fromCell);
  773.     if (link)
  774.         link->SetCell(ev, toCell);
  775. }
  776.  
  777.